package cn.dnui_xcz826.dnuifood_16110100826.fragments;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import java.util.List;

import cn.dnui_xcz826.dnuifood_16110100826.R;
import cn.dnui_xcz826.dnuifood_16110100826.adapter.CollectAdapter;
import cn.dnui_xcz826.dnuifood_16110100826.bean.CollectBean;
import cn.dnui_xcz826.dnuifood_16110100826.listener.onRetrofitListener;
import cn.dnui_xcz826.dnuifood_16110100826.model.CollectModel;

public class CollectFoodFragment extends BaseFragment implements onRetrofitListener <List<CollectBean>> {
    private RecyclerView collect_rv;
    private CollectAdapter adapter;
    private CollectModel collectModel;

    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle
            savedInstanceState) {
        setLayout_file(R.layout.collect_shop_food_fragment);
        View view=inflater.inflate(R.layout.collect_shop_food_fragment,container,false);
        //TextView tv=view.findViewById(R.id.tv_tv);
        collect_rv = (RecyclerView) view.findViewById(R.id.collect_rv);
        collect_rv.setLayoutManager(new LinearLayoutManager(getActivity()));
        initViews();
        initData();
        return view;

    }

    void initViews() {
        collect_rv.setHasFixedSize(true);
    }

    @Override
    void initEvents() {
    }

    void initData() {
        collectModel = new CollectModel();
        collectModel.getAllUserCollection(getUser_id(), "1", this);
    }

    @Override
    public void onSuccess(List<CollectBean> collectInfos, int flag) {
        adapter = new CollectAdapter(context, collectInfos, R.layout.collect_item);
        collect_rv.setAdapter(adapter);
    }

    @Override
    public void onFailure(String msg) {
        Toast.makeText(context, "失败：" + msg, Toast.LENGTH_SHORT).show();
    }

}